package com.steven.im.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.steven.im.R;
import com.steven.im.entity.IMGroupNameEntity;

import java.util.ArrayList;
import java.util.List;

public class IMGroupAdapter extends BaseQuickAdapter<IMGroupNameEntity, BaseViewHolder> {
    private List<IMGroupNameEntity> list;
    private List<ImageView> ivList;
    private TextView tvGroupName;

    public IMGroupAdapter(List<IMGroupNameEntity> item, TextView tvGroupName) {
        super(R.layout.item_groupname, item);
        this.list = item;
        this.ivList = new ArrayList<>();
        this.tvGroupName = tvGroupName;
    }

    @Override
    protected void convert(final BaseViewHolder helper, IMGroupNameEntity item) {
        ImageView iv_select = helper.getView(R.id.iv_select);
        ivList.add(iv_select);
        if (helper.getPosition() == 0) {
            tvGroupName.setText(list.get(0).getName());
            iv_select.setVisibility(View.VISIBLE);
        }
        ((TextView) helper.getView(R.id.tv_name)).setText(list.get(helper.getPosition()).getName());
        RelativeLayout rl_item = helper.getView(R.id.rl_item);
        rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击设置对号
                for (int i = 0; i < ivList.size(); i++) {
                    if (helper.getPosition() == i) {
                        tvGroupName.setText(list.get(helper.getPosition()).getName());
                        ivList.get(i).setVisibility(View.VISIBLE);
                    } else {
                        ivList.get(i).setVisibility(View.GONE);
                    }
                }
            }
        });
    }

}
